<?php
namespace utils\action;

use herosphp\core\Controller;
use herosphp\http\HttpRequest;
use herosphp\image\VerifyCode;
use herosphp\session\Session;

/**
 * 验证码 Action
 * @author          yangjian<yangjian102621@gmail.com>
 */
class VerifyCodeAction extends Controller {

    public function index(HttpRequest $request) {
        $size = $request->getParameter('s', 'trim');
        $verify = VerifyCode::getInstance();
        Session::start();
        switch ($size) {
            case 0:
                $config = array('x'=>10, 'y'=>25, 'w'=>90, 'h'=>36, 'f'=>20);
                $_SESSION['scode'] = strtoupper($verify->configure($config)->generate(4));
                break;
            case 1:
				$config = array('x'=>10, 'y'=>25, 'w'=>100, 'h'=>32, 'f'=>20);
                $_SESSION['scode'] = strtoupper($verify->configure($config)->generate(4));
                break;
        }
		$_SESSION['scode_time'] = time(0);
        $verify->show('png');
        die();
    }
}
